package cn.org.xuanguang.kepler.hormos.rdb.dml.operator;

import cn.org.xuanguang.kepler.hormos.rdb.dsl.sql.SqlRequest;
import cn.org.xuanguang.kepler.hormos.rdb.dsl.sql.SqlRequests;
import cn.org.xuanguang.kepler.hormos.rdb.executor.SyncSqlExecutor;

/**
 * 原生DML操作
 *
 * @param <T> 返回值类型
 */
public class NativeDmlOperator<T> implements DmlOperator<T> {

    SqlRequest sqlRequest = null;
    /**
     * SyncSqlExecutor
     */
    private SyncSqlExecutor syncSqlExecutor;

    private NativeDmlOperator(SyncSqlExecutor syncSqlExecutor) {
        this.syncSqlExecutor = syncSqlExecutor;
    }

    public static NativeDmlOperator of(SyncSqlExecutor syncSqlExecutor) {
        return new NativeDmlOperator(syncSqlExecutor);
    }

    public NativeDmlOperator sql(String sql, Object... parameters) {
        sqlRequest = SqlRequests.of(sql, parameters);
        return this;
    }

    public NativeDmlOperator sql(SqlRequest sqlRequest) {
        this.sqlRequest = sqlRequest;
        return this;
    }

    @Override
    public SqlRequest getSql() {
        return sqlRequest;
    }

    @Override
    public T execute() {
        if (sqlRequest == null) {
            throw new IllegalStateException("navtive sql is not null!");
        }
        return null;
    }
}
